from evalsupport import deco_alpha
from evalsupport import MetaAleph

print("<[1]> evaltime_meta module start")


@deco_alpha
class ClassThree:
    print("<[2]> ClassThree body")

    def method_y(self):
        print("<[3]> ClassThree.method_y")


class ClassFour(ClassThree):
    print("<[4]> ClassFour body")

    def method_y(self):
        print("<[5]> ClassFour.method_y")


# 指定元类要创建 其元类实例,即MetaAleph.__init__
class ClassFive(metaclass=MetaAleph):
    print("<[6]> ClassFive body, metaclass 元类MetaAleph构造")

    def __init__(self):
        print("<[7]> ClassFive.__init__ inherited by", self.__class__.__name__)

    def method_z(self):
        print("<[8]> ClassFive.method_z")


class ClassFive_byInherit(MetaAleph):
    print("<ClassFive_byInherit 身体,继承不会执行元类构造")


# 继承元类,或者元类的子类
class ClassSix(ClassFive):
    print("<[9]> ClassSix body,因为继承类使用元类构造...")

    def method_z(self):
        print("<[10]> ClassSix.method_y")


if __name__ == "__main__":
    print("<[11]> ClassThree tests", 30 * ".")
    three = ClassThree()
    three.method_y()
    print("<[12]> ClassFour tests", 30 * ".")
    four = ClassFour()
    four.method_y()
    print("<[13]> ClassFive tests", 30 * ".")
    five = ClassFive()
    five.method_z()
    print("<[14]> ClassSix tests", 30 * ".")
    six = ClassSix()
    six.method_z()

print("<[15]> evaltime_meta module end")

# 导入  evaltime_meta.py 顺序
"""
<[100]> evalsupport module start
<[400]> MetaAleph body
<[700]> evalsupport module end
<[evalsupport]>
<[1]> evaltime_meta module start
<[2]> ClassThree body
<[200]> deco_alpha
<[4]> ClassFour body
<[6]> ClassFive body, metaclass 元类MetaAleph构造
<[500]> MetaAleph.__init__ <class ClassFive> ClassFive (空) {'__module__': 'evaltime_meta', '__qualname__': 'ClassFive', '__init__': <function ClassFive.__init__ at 0x102705280>, 'method_z': <function ClassFive.method_z at 0x102705310>}
<ClassFive_byInherit 身体,继承不会执行元类构造
<[9]> ClassSix body,因为继承类使用元类构造...
<[500]> MetaAleph.__init__ <class ClassSix> ClassSix (<class ClassFive>,) {'__module__': 'evaltime_meta', '__qualname__': 'ClassSix', 'method_z': <function ClassSix.method_z at 0x102705310>}
<[15]> evaltime_meta module end
执行阶段
<[100]> evalsupport module start
<[400]> MetaAleph body
<[700]> evalsupport module end
<[evalsupport]>
<[1]> evaltime_meta module start
<[2]> ClassThree body
<[200]> deco_alpha
<[4]> ClassFour body
<[6]> ClassFive body, metaclass 元类MetaAleph构造
<[500]> MetaAleph.__init__ <class ClassFive> ClassFive (空) {'__module__': 'evaltime_meta', '__qualname__': 'ClassFive', '__init__': <function ClassFive.__init__ at 0x102705280>, 'method_z': <function ClassFive.method_z at 0x102705310>}
<ClassFive_byInherit 身体,继承不会执行元类构造
<[9]> ClassSix body,因为继承类使用元类构造...
11 ************Three Tests
<[300]> deco_alpha:inner_1, 旧的类被替换
12 ****** 测试 Four
<[5]> ClassFour.method_y
13 ******** 测试 Five
<[7]> ClassFive.__init__ inherited by ClassFive
#### <[8]> ClassFive.method_z 不会执行
... <[600]> MetaAleph.__init__:inner_2
    self is <__main__.ClassFive object at 0x101905040>
    cls is <class '__main__.ClassFive'>
    self.__class__ <class '__main__.ClassFive'>

14 **** 测试 six
<[7]> ClassFive.__init__ inherited by ClassSix FIXME 最容易坑的地方, ClassSix会调用ClassFive的构造方法
<[600]> MetaAleph.__init__:inner_2
self is <__main__.ClassSix object at 0x1008902e0>
cls is <class '__main__.ClassSix'>
self.__class__ <class '__main__.ClassSix'>

<[15]> evaltime_meta module end
#### <[10]> ClassSix.method_y 不会执行
... inner2 logic

"""
